package com.yanqu.road.entity.config.promotion;

import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.config.promotion.emnus.ePromotionBigType;
import com.yanqu.road.entity.config.promotion.emnus.ePromotionType;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;

@FieldTypeAnnotation(tableName = "t_p_promotion")
public class PromotionInfo {

    @FieldTypeAnnotation(desc = "晋升id")
    private int id;

    @FieldTypeAnnotation(desc = "晋升类型")
    private int type;

    @FieldTypeAnnotation(desc = "晋升参数列表")
    private String paramList;

    @FieldTypeAnnotation(desc = "下次晋升id")
    private int nextId;

    @FieldTypeAnnotation(desc = "晋升角色id", select = true)
    private int characterId;

    @FieldTypeAnnotation(desc = "晋升后品质")
    private int quality;

    @FieldTypeAnnotation(desc = "初始属性")
    private String defaultAttribute;

    @FieldTypeAnnotation(desc = "技能列表")
    private List<Integer> skillList = new ArrayList<>();

    @FieldTypeAnnotation(desc = "天赋列表")
    private List<Integer> talentList = new ArrayList<>();

    @FieldTypeAnnotation(desc = "是否可精进")
    private int canStage;

    @FieldTypeAnnotation(desc = "晋升奖励")
    private String reward;

    @FieldTypeAnnotation(desc = "扩展参数，美女无双晋升类型（11，13）:晋升后可自选X个新缘分|0|0|0")
    private String extendParam;

    private int peerlessSkillId;

    private int promotionSkillId;

    private ItemPeerlessPromotionInfo itemPeerlessPromotionInfo;

    /**
     * 自选缘分门客孔位数量
     */
    private int selfSelectPatronsPositionNum = 0;


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getParamList() {
        return paramList;
    }

    public void setParamList(String paramList) {
        this.paramList = paramList;
    }

    public String getExtendParam() {
        return extendParam;
    }

    public void setExtendParam(String extendParam) {
        this.extendParam = extendParam;
    }

    public int getNextId() {
        return nextId;
    }

    public void setNextId(int nextId) {
        this.nextId = nextId;
    }

    public int getCharacterId() {
        return characterId;
    }

    public void setCharacterId(int characterId) {
        this.characterId = characterId;
    }

    public int getQuality() {
        return quality;
    }

    public void setQuality(int quality) {
        this.quality = quality;
    }

    public String getDefaultAttribute() {
        return defaultAttribute;
    }

    public void setDefaultAttribute(String defaultAttribute) {
        this.defaultAttribute = defaultAttribute;
    }

    public List<Integer> getSkillList() {
        return skillList;
    }

    public void setSkillList(List<Integer> skillList) {
        this.skillList = skillList;
    }

    public List<Integer> getTalentList() {
        return talentList;
    }

    public void setTalentList(List<Integer> talentList) {
        this.talentList = talentList;
    }

    public int getCanStage() {
        return canStage;
    }

    public void setCanStage(int canStage) {
        this.canStage = canStage;
    }

    public int getPeerlessSkillId() {
        if (peerlessSkillId == 0) {
            if (type == 11) {
                //示例配置：1;1|4;1=60101=1;2|4;2#1;3|4;3
                String[] arrStrs = getParamList().split("=");
                if (arrStrs.length < 3) {
                    return 0;
                }
                peerlessSkillId = Integer.parseInt(arrStrs[1]);
            } else if (type == 13) {
                ItemPeerlessPromotionInfo peerlessPromotionInfo = getItemPeerlessPromotionInfo();
                if (peerlessPromotionInfo != null) {
                    return peerlessPromotionInfo.getPeerlessSkillId();
                }
            }
        }
        return peerlessSkillId;
    }

    public String getReward() {
        return reward;
    }

    public void setReward(String reward) {
        this.reward = reward;
    }

    public int getSelfSelectPatronsPositionNum() {
        if (selfSelectPatronsPositionNum == 0) {
            //晋升大类型属于美女晋升，selfSelectPatronsPositionNum就需要解析
            int bigType = ePromotionType.getBigType(this.type);
            if (bigType == ePromotionBigType.PROMOTION_BIG_TYPE_BEAUTY.getType()) {
                if (!StringUtils.isNullOrEmpty(this.getExtendParam())) {
                    String[] arr = this.getExtendParam().split("\\|");
                    selfSelectPatronsPositionNum = Integer.parseInt(arr[0]);
                }
            }
        }
        return selfSelectPatronsPositionNum;
    }

    public ItemPeerlessPromotionInfo getItemPeerlessPromotionInfo() {
        if (this.type != 13) {
            return null;
        }
        if (itemPeerlessPromotionInfo == null) {
            itemPeerlessPromotionInfo = new ItemPeerlessPromotionInfo(this.paramList);
        }
        return itemPeerlessPromotionInfo;
    }
}
